<?php
/**
 * Created by PhpStorm.
 * Clerk: Administrator
 * Date: 2018/8/24
 * Time: 15:53
 */

namespace app\api\controller\v1;
use app\api\controller\BaseController;
use app\api\model\Banner;
use app\api\model\Client;
use app\api\model\Goods;
use think\Session;

class Order extends BaseController
{


    /**
     * 我的订单
     */
    public function myOrder(){
        $token = $token = $this->request->header('token');
        if(Session::has($token)){
          $clerk_id = Session::get($token);
          $order_status = $this->request->post('order_status');
          if(empty($order_status)){
              return json_failed(100006);
          }
          if(in_array($order_status,[2,3,4])){ //2--待发货，3--已发货，4--订单完成
              $order_list = \app\api\model\Order::getOrderList($order_status,$clerk_id);
              return json_success($order_list);
          }else{
              return json_failed(100005);
          }

        }else{
            return json_failed(401);
        }

    }

    /**
     * 我的统计
     */
    public function myCount(){
        $token = $token = $this->request->header('token');
        if(Session::has($token)){
            $clerk_id = Session::get($token);
            $cycle = $this->request->post('cycle');
            if(empty($cycle)){
                return json_failed(100007);
            }
            if($cycle == 'week'){
                $time = \Time::week();
            }elseif($cycle == 'month'){
                $time = \Time::month();
            }elseif($cycle == 'year'){
                $time = \Time::year();
            }else{
                return json_failed(100008);
            }
            $sum_money = \app\api\model\Order::getSumMoney($clerk_id,$time);
            $order_detail = \app\api\model\Order::getOrderDetail($clerk_id,$time);
            $data = [
              'sum_money'=>$sum_money,
              'order_detail'=>$order_detail
            ];
            return json_success($data);

        }else{
            return json_failed(401);
        }


    }


}